import React, { useState, useEffect } from 'react'
import { View, Image, Text } from '@tarojs/components'
import { AtTabs, AtIcon } from 'taro-ui'
import ToLogin from '../../compontents/toLogin'
import Taro from '@tarojs/taro'
import useModel from 'flooks';
import store from '../../stores/index'
import api from '../../http/api'
const { nsTelText } = api
import './index.less'


export default (props: any) => {
  const info: any = Taro.getStorageSync('info')
  const uSchoolId = info ? JSON.parse(info).userInfo.uSchoolId : 0

  const { nsTelInfo, nsTelInfoChange } = useModel(store.nsTelInfo, ['nsTelInfo'])
  
  const id:any = props.tid.split('nsBusinessId=')[1].split('&')[0]
  const nsTypeId = props.tid.split('nsTypeId=')[1].split('&')[0]

  const [list, setList] = useState([])
  
  useEffect(() => {
    nsTelText({uSchoolId}).then((res:any)=>{
        setList(res.data)
    })
  }, [])

  const telLiClick = (item:any,i:number)=>{
    Taro.navigateTo({
      url:`/pages/nsBusinessDetail/index?nsBusinessId=${id}&nsTypeId=${nsTypeId}&telType=${item.id}&price=${item.price}&infoList=${item.infoList}`
    })
    const storeJson = {...nsTelInfo}
    storeJson.cont = item.cont
    nsTelInfoChange(storeJson)
  }
 
  return (
    <View className='nsTel'>
      <ToLogin url={`/pages/nsBusinessDetail/nsTel`}></ToLogin>
        <View className="telUl">
          {
            list.map((item:any,i:number)=>(
              <View onClick={()=>{telLiClick(item,i)}} className="telLi">
                  <Image className='img' src={item.src} ></Image>
                  <View className="title">{item.title}</View>
                  {
                    item.cont.split('|').map((item)=>(
                      <View className="cont">{item}</View>
                    ))
                  }
                  
              </View>
            ))
          }
      </View>
    </View>
  );
};
